/**
 * @description 装饰模式
 */

/**
 * @description 学校给家长的报告
 */
interface SchoolReport {
  report(): void
  sign(name: string): void
}

class ForthGradeSchoolReport implements SchoolReport {
  report(): void {
    console.log('尊敬的xxx家长:');
    console.log('......');
    console.log(' 语文 62  数学65  体育98  自然 63');
    console.log('......');
    console.log('              家长签字:     ');
    console.log('');
    console.log('');
    console.log('');
  }
  sign(name: string): void {
    console.log('家长签名为: ' + name);
  }
}

abstract class Decorator implements SchoolReport {
  _sr: SchoolReport = null;
  constructor(sr: SchoolReport) {
    this._sr = sr
  }
  report(): void {
    this._sr.report() // 这一步妙啊
  }
  sign(name: string): void {
    this._sr.sign(name)
  }
}

/**
 * @description 最高分装饰
 */
class HighScoreDecorator extends Decorator {
  constructor(sr: SchoolReport) {
    super(sr)
  }
  private reportHighScore(): void {
    console.log('提前告知最高分是75分');
  }

  report(): void {
    this.reportHighScore()
    super.report()
  }
}

/**
 * @description 排名装饰
 */
class SortDecorator extends Decorator {
  constructor(sr: SchoolReport) {
    super(sr)
  }
  private reportSort(): void {
    console.log('我排名38名');
  }

  report(): void {
    super.report()
    this.reportSort()
  }
}



function main() {
  let sr = new ForthGradeSchoolReport()
  sr = new HighScoreDecorator(sr)
  sr = new SortDecorator(sr)

  sr.report()
  sr.sign('老王')
}
main()